package auxiliary;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;

import structure.Frame;
import structure.Point;


public class InputReader {

	public ArrayList<Frame> read(String filePath){
		ArrayList<Frame> frames = new ArrayList<Frame>();
		
		try {
			Frame frame = null;
			BufferedReader br = new BufferedReader(new FileReader(filePath));
			String line;
			while((line = br.readLine()) != null ){
				String[] splittedLine = line.split(",");
				//new frame
				if(splittedLine.length == 1){
					if(frame != null)
						frames.add(frame);
					frame = new Frame(splittedLine[0]);
				} else {
					Point p = new Point(Double.parseDouble(splittedLine[0]), Double.parseDouble(splittedLine[1]));
					frame.addPoint(p);
				}
			}
			br.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		return frames;
	}
	
}